// 2025/10/26
// 组合

class Solution {
public:
    vector<vector<int>> ans;
    vector<bool> isUsed;
    vector<int> tmp;

    void dfs(int begin, int k)
    {
        if(k == 0)
        {
            ans.push_back(tmp);
            return;
        }
        
        for(int i = begin; i < isUsed.size(); i++)
        {
            if(!isUsed[i])
            {
                tmp.emplace_back(i);
                isUsed[i] = true;
                dfs(i + 1, k - 1);
                isUsed[i] = false;
                tmp.pop_back();
            }
        }
    }

    vector<vector<int>> combine(int n, int k) {
        isUsed.resize(n + 1, false);
        dfs(1, k);
        return ans;
    }
};